package com.xfg.search.serviceImpl;

import com.xfg.search.dao.AdminDao;
import com.xfg.search.entity.ChineseDrug;
import com.xfg.search.entity.Oil;
import com.xfg.search.entity.User;
import com.xfg.search.service.AdminService;
import com.xfg.search.utils.Excel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.InputStream;
import java.util.List;

@Service
@Transactional
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminDao adminDao;
    @Override
    public User login(String uname, String password) {
        return adminDao.findByNameAndPwd(uname,password);
    }

    @Override
    public boolean importInfo(String fileName, InputStream is,Integer id) throws Exception {
        Excel excel=new Excel();
        if(id==1){
            List<Oil> oilList = excel.uploadOil(fileName, is);
            int row=adminDao.addOil(oilList);
            List<Oil> oilList1 = excel.uploadOil(fileName, is);
            int row1=adminDao.addOil(oilList);
            List<Oil> oilList2 = excel.uploadOil(fileName, is);
            int row2=adminDao.addOil(oilList);
        }else if(id==2){
            List<ChineseDrug> chineseDrugList = excel.uploadDrug(fileName, is);
            int row=adminDao.addChineseDrug(chineseDrugList);
        }else if(id==3){

        }else if(id==4){

        }else if(id==5){

        }else if(id==6){

        }else {

        }
        List<User> userList = excel.upload(fileName, is);
        int row=adminDao.addUser(userList);
        if(row>0){
            return true;
        }else {
            return false;
        }

    }
}
